package com.zzyl.nursing.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.CateringWeeklyMenu;
import com.zzyl.nursing.domain.CateringCareMenu;
import com.zzyl.nursing.domain.CateringFeedback;
import com.zzyl.nursing.service.ICateringWeeklyMenuService;
import com.zzyl.nursing.service.ICateringCareMenuService;
import com.zzyl.nursing.service.ICateringFeedbackService;

/**
 * 餐饮管理Controller
 * 
 * @author alexis
 * @date 2024-12-30
 */
@Api(tags = "餐饮管理")
@RestController
@RequestMapping("/catering")
public class CateringController extends BaseController
{
    @Autowired
    private ICateringWeeklyMenuService cateringWeeklyMenuService;

    @Autowired
    private ICateringCareMenuService cateringCareMenuService;

    @Autowired
    private ICateringFeedbackService cateringFeedbackService;

    // ==================== 每周食谱管理 ====================

    /**
     * 查询每周食谱列表
     */
    @ApiOperation("查询每周食谱列表")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:list')")
    @GetMapping("/weeklyMenu/list")
    public TableDataInfo<List<CateringWeeklyMenu>> listWeeklyMenu(@ApiParam("每周食谱查询条件") CateringWeeklyMenu cateringWeeklyMenu)
    {
        startPage();
        List<CateringWeeklyMenu> list = cateringWeeklyMenuService.selectCateringWeeklyMenuList(cateringWeeklyMenu);
        return getDataTable(list);
    }

    /**
     * 导出每周食谱列表
     */
    @ApiOperation("导出每周食谱列表")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:export')")
    @Log(title = "每周食谱", businessType = BusinessType.EXPORT)
    @PostMapping("/weeklyMenu/export")
    public void exportWeeklyMenu(@ApiParam(value = "每周食谱查询条件") HttpServletResponse response, CateringWeeklyMenu cateringWeeklyMenu)
    {
        List<CateringWeeklyMenu> list = cateringWeeklyMenuService.selectCateringWeeklyMenuList(cateringWeeklyMenu);
        ExcelUtil<CateringWeeklyMenu> util = new ExcelUtil<CateringWeeklyMenu>(CateringWeeklyMenu.class);
        util.exportExcel(response, list, "每周食谱数据");
    }

    /**
     * 获取每周食谱详细信息
     */
    @ApiOperation("获取每周食谱详细信息")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:query')")
    @GetMapping(value = "/weeklyMenu/{id}")
    public R<CateringWeeklyMenu> getWeeklyMenuInfo(@ApiParam("每周食谱ID") @PathVariable("id") Long id)
    {
        return R.ok(cateringWeeklyMenuService.selectCateringWeeklyMenuById(id));
    }

    /**
     * 新增每周食谱
     */
    @ApiOperation("新增每周食谱")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:add')")
    @Log(title = "每周食谱", businessType = BusinessType.INSERT)
    @PostMapping("/weeklyMenu/save")
    public AjaxResult addWeeklyMenu(@ApiParam("每周食谱信息") @RequestBody CateringWeeklyMenu cateringWeeklyMenu)
    {
        return toAjax(cateringWeeklyMenuService.insertCateringWeeklyMenu(cateringWeeklyMenu));
    }

    /**
     * 修改每周食谱
     */
    @ApiOperation("修改每周食谱")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:edit')")
    @Log(title = "每周食谱", businessType = BusinessType.UPDATE)
    @PutMapping("/weeklyMenu/save")
    public AjaxResult editWeeklyMenu(@ApiParam("每周食谱信息") @RequestBody CateringWeeklyMenu cateringWeeklyMenu)
    {
        return toAjax(cateringWeeklyMenuService.updateCateringWeeklyMenu(cateringWeeklyMenu));
    }

    /**
     * 删除每周食谱
     */
    @ApiOperation("删除每周食谱")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:remove')")
    @Log(title = "每周食谱", businessType = BusinessType.DELETE)
    @DeleteMapping("/weeklyMenu/remove/{id}")
    public AjaxResult removeWeeklyMenu(@ApiParam("每周食谱ID") @PathVariable Long id)
    {
        return toAjax(cateringWeeklyMenuService.deleteCateringWeeklyMenuById(id));
    }

    /**
     * 批量删除每周食谱
     */
    @ApiOperation("批量删除每周食谱")
    @PreAuthorize("@ss.hasPermi('catering:weeklyMenu:remove')")
    @Log(title = "每周食谱", businessType = BusinessType.DELETE)
    @DeleteMapping("/weeklyMenu/remove")
    public AjaxResult removeWeeklyMenus(@ApiParam("每周食谱ID数组") @RequestBody Long[] ids)
    {
        return toAjax(cateringWeeklyMenuService.deleteCateringWeeklyMenuByIds(ids));
    }

    /**
     * 上传每周食谱图片
     */
    @ApiOperation("上传每周食谱图片")
    @PostMapping("/weeklyMenu/upload")
    public AjaxResult uploadWeeklyMenuImage(@ApiParam("图片文件") @RequestParam("file") MultipartFile file)
    {
        return cateringWeeklyMenuService.uploadDishImage(file);
    }

    // ==================== 关怀食谱管理 ====================

    /**
     * 查询关怀食谱列表
     */
    @ApiOperation("查询关怀食谱列表")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:list')")
    @GetMapping("/careMenu/list")
    public TableDataInfo<List<CateringCareMenu>> listCareMenu(@ApiParam("关怀食谱查询条件") CateringCareMenu cateringCareMenu)
    {
        startPage();
        List<CateringCareMenu> list = cateringCareMenuService.selectCateringCareMenuList(cateringCareMenu);
        return getDataTable(list);
    }

    /**
     * 导出关怀食谱列表
     */
    @ApiOperation("导出关怀食谱列表")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:export')")
    @Log(title = "关怀食谱", businessType = BusinessType.EXPORT)
    @PostMapping("/careMenu/export")
    public void exportCareMenu(@ApiParam(value = "关怀食谱查询条件") HttpServletResponse response, CateringCareMenu cateringCareMenu)
    {
        List<CateringCareMenu> list = cateringCareMenuService.selectCateringCareMenuList(cateringCareMenu);
        ExcelUtil<CateringCareMenu> util = new ExcelUtil<CateringCareMenu>(CateringCareMenu.class);
        util.exportExcel(response, list, "关怀食谱数据");
    }

    /**
     * 获取关怀食谱详细信息
     */
    @ApiOperation("获取关怀食谱详细信息")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:query')")
    @GetMapping(value = "/careMenu/{id}")
    public R<CateringCareMenu> getCareMenuInfo(@ApiParam("关怀食谱ID") @PathVariable("id") Long id)
    {
        return R.ok(cateringCareMenuService.selectCateringCareMenuById(id));
    }

    /**
     * 新增关怀食谱
     */
    @ApiOperation("新增关怀食谱")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:add')")
    @Log(title = "关怀食谱", businessType = BusinessType.INSERT)
    @PostMapping("/careMenu/save")
    public AjaxResult addCareMenu(@ApiParam("关怀食谱信息") @RequestBody CateringCareMenu cateringCareMenu)
    {
        return toAjax(cateringCareMenuService.insertCateringCareMenu(cateringCareMenu));
    }

    /**
     * 修改关怀食谱
     */
    @ApiOperation("修改关怀食谱")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:edit')")
    @Log(title = "关怀食谱", businessType = BusinessType.UPDATE)
    @PutMapping("/careMenu/save")
    public AjaxResult editCareMenu(@ApiParam("关怀食谱信息") @RequestBody CateringCareMenu cateringCareMenu)
    {
        return toAjax(cateringCareMenuService.updateCateringCareMenu(cateringCareMenu));
    }

    /**
     * 删除关怀食谱
     */
    @ApiOperation("删除关怀食谱")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:remove')")
    @Log(title = "关怀食谱", businessType = BusinessType.DELETE)
    @DeleteMapping("/careMenu/remove/{id}")
    public AjaxResult removeCareMenu(@ApiParam("关怀食谱ID") @PathVariable Long id)
    {
        return toAjax(cateringCareMenuService.deleteCateringCareMenuById(id));
    }

    /**
     * 批量删除关怀食谱
     */
    @ApiOperation("批量删除关怀食谱")
    @PreAuthorize("@ss.hasPermi('catering:careMenu:remove')")
    @Log(title = "关怀食谱", businessType = BusinessType.DELETE)
    @DeleteMapping("/careMenu/remove")
    public AjaxResult removeCareMenus(@ApiParam("关怀食谱ID数组") @RequestBody Long[] ids)
    {
        return toAjax(cateringCareMenuService.deleteCateringCareMenuByIds(ids));
    }

    /**
     * 上传关怀食谱图片
     */
    @ApiOperation("上传关怀食谱图片")
    @PostMapping("/careMenu/upload")
    public AjaxResult uploadCareMenuImage(@ApiParam("图片文件") @RequestParam("file") MultipartFile file)
    {
        return cateringCareMenuService.uploadDishImage(file);
    }

    /**
     * 根据类型查询关怀食谱
     */
    @ApiOperation("根据类型查询关怀食谱")
    @GetMapping("/careMenu/type/{menuType}")
    public R<List<CateringCareMenu>> getCareMenuByType(@ApiParam("食谱类型") @PathVariable Integer menuType)
    {
        return R.ok(cateringCareMenuService.selectCareMenuByType(menuType));
    }

    // ==================== 用餐反馈管理 ====================

    /**
     * 查询用餐反馈列表
     */
    @ApiOperation("查询用餐反馈列表")
    @PreAuthorize("@ss.hasPermi('catering:feedback:list')")
    @GetMapping("/feedback/list")
    public TableDataInfo<List<CateringFeedback>> listFeedback(@ApiParam("用餐反馈查询条件") CateringFeedback cateringFeedback)
    {
        startPage();
        List<CateringFeedback> list = cateringFeedbackService.selectCateringFeedbackList(cateringFeedback);
        return getDataTable(list);
    }

    /**
     * 导出用餐反馈列表
     */
    @ApiOperation("导出用餐反馈列表")
    @PreAuthorize("@ss.hasPermi('catering:feedback:export')")
    @Log(title = "用餐反馈", businessType = BusinessType.EXPORT)
    @PostMapping("/feedback/export")
    public void exportFeedback(@ApiParam(value = "用餐反馈查询条件") HttpServletResponse response, CateringFeedback cateringFeedback)
    {
        List<CateringFeedback> list = cateringFeedbackService.selectCateringFeedbackList(cateringFeedback);
        ExcelUtil<CateringFeedback> util = new ExcelUtil<CateringFeedback>(CateringFeedback.class);
        util.exportExcel(response, list, "用餐反馈数据");
    }

    /**
     * 获取用餐反馈详细信息
     */
    @ApiOperation("获取用餐反馈详细信息")
    @PreAuthorize("@ss.hasPermi('catering:feedback:query')")
    @GetMapping(value = "/feedback/{id}")
    public R<CateringFeedback> getFeedbackInfo(@ApiParam("用餐反馈ID") @PathVariable("id") Long id)
    {
        return R.ok(cateringFeedbackService.selectCateringFeedbackById(id));
    }

    /**
     * 新增用餐反馈
     */
    @ApiOperation("新增用餐反馈")
    @PreAuthorize("@ss.hasPermi('catering:feedback:add')")
    @Log(title = "用餐反馈", businessType = BusinessType.INSERT)
    @PostMapping("/feedback/save")
    public AjaxResult addFeedback(@ApiParam("用餐反馈信息") @RequestBody CateringFeedback cateringFeedback)
    {
        return toAjax(cateringFeedbackService.insertCateringFeedback(cateringFeedback));
    }

    /**
     * 修改用餐反馈
     */
    @ApiOperation("修改用餐反馈")
    @PreAuthorize("@ss.hasPermi('catering:feedback:edit')")
    @Log(title = "用餐反馈", businessType = BusinessType.UPDATE)
    @PutMapping("/feedback/save")
    public AjaxResult editFeedback(@ApiParam("用餐反馈信息") @RequestBody CateringFeedback cateringFeedback)
    {
        return toAjax(cateringFeedbackService.updateCateringFeedback(cateringFeedback));
    }

    /**
     * 删除用餐反馈
     */
    @ApiOperation("删除用餐反馈")
    @PreAuthorize("@ss.hasPermi('catering:feedback:remove')")
    @Log(title = "用餐反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/feedback/remove/{id}")
    public AjaxResult removeFeedback(@ApiParam("用餐反馈ID") @PathVariable Long id)
    {
        return toAjax(cateringFeedbackService.deleteCateringFeedbackById(id));
    }

    /**
     * 批量删除用餐反馈
     */
    @ApiOperation("批量删除用餐反馈")
    @PreAuthorize("@ss.hasPermi('catering:feedback:remove')")
    @Log(title = "用餐反馈", businessType = BusinessType.DELETE)
    @DeleteMapping("/feedback/remove")
    public AjaxResult removeFeedbacks(@ApiParam("用餐反馈ID数组") @RequestBody Long[] ids)
    {
        return toAjax(cateringFeedbackService.deleteCateringFeedbackByIds(ids));
    }

    /**
     * 回复用餐反馈
     */
    @ApiOperation("回复用餐反馈")
    @PreAuthorize("@ss.hasPermi('catering:feedback:reply')")
    @Log(title = "回复用餐反馈", businessType = BusinessType.UPDATE)
    @PostMapping("/feedback/reply")
    public AjaxResult replyFeedback(@ApiParam("用餐反馈回复信息") @RequestBody CateringFeedback cateringFeedback)
    {
        return toAjax(cateringFeedbackService.replyCateringFeedback(cateringFeedback));
    }

    /**
     * 上传用餐反馈图片
     */
    @ApiOperation("上传用餐反馈图片")
    @PostMapping("/feedback/upload")
    public AjaxResult uploadFeedbackImage(@ApiParam("图片文件") @RequestParam("file") MultipartFile file)
    {
        return cateringFeedbackService.uploadFeedbackImage(file);
    }

    /**
     * 根据老人ID查询反馈列表
     */
    @ApiOperation("根据老人ID查询反馈列表")
    @GetMapping("/feedback/elder/{elderId}")
    public R<List<CateringFeedback>> getFeedbackByElderId(@ApiParam("老人ID") @PathVariable Long elderId)
    {
        return R.ok(cateringFeedbackService.selectFeedbackByElderId(elderId));
    }

    /**
     * 根据处理状态查询反馈列表
     */
    @ApiOperation("根据处理状态查询反馈列表")
    @GetMapping("/feedback/status/{status}")
    public R<List<CateringFeedback>> getFeedbackByStatus(@ApiParam("处理状态") @PathVariable Integer status)
    {
        return R.ok(cateringFeedbackService.selectFeedbackByStatus(status));
    }
} 